package cn.webrx;

public class Switch2 {
    public static void main(String[] args) {
        //根据月份，输出这个月有多少天
        int y = 2023;
        int m = 2;

        //switch表达式 -> {yield 常量}
        int days = switch (m) {
            case 1, 3, 5, 7, 8, 10, 12 -> 31;
            case 4, 6, 9, 11 -> 30;
            default -> {
                int d = 28;
                if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0) {
                    d = 29;
                }
                yield d;
            }
        };
        System.out.printf("%d年%d月有%d天。", y, m, days);
    }

    public static void bb(String[] args) {
        //根据月份，输出这个月有多少天
        int y = 2020;
        int m = 2;
        int days = 0;
        switch (m) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                days = 31;
                break;

            case 4:
            case 6:
            case 9:
            case 11:
                days = 30;
                break;
            default:
                days = y % 400 == 0 || y % 4 == 0 && y % 100 != 0 ? 29 : 28;
                break;
        }
        System.out.printf("%d年%d月有%d天。", y, m, days);

    }

    public static void aa(String[] args) {
        int k = 3;
        //多分支开关语句
        switch (k) {
            case 3:
                System.out.println("3");
                break;

            case 2:
                System.out.println("2");
                break;

            case 1:
                System.out.println("1");
                break;

            case 10:
                System.out.println("10");
                break;
            default:
                System.out.println("default");
                break;
        }
    }
}
